<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<style>
.all_list select {
	width: 120px;
}
</style>
<div class="r_location">
	<i class="r_txtico"></i> 活动内容管理&gt; 奖品管理 
</div>
<div class="m-t10">
	<div class="clearfix table_fn">
			<span class="l">奖品管理数据列表</span> <span class="r"
				style="_margin-top: 5px;"> <a href="#" title="" class="add_ico" onclick="addPrize()" id="add_term">新增</a>
			</span>
	</div>
	<table id="prize_table">
	</table>
	<div id="pgtoolbar"></div>
</div>
<script>
function addPrize() {
	to_page('/cms/prize/add/page');
}
	function deletePrize(id){
		art.dialog({
			title : '删除奖品',
			lock : true,
			content : '确认删除奖品?',
			width : '200px',
		    cancelVal: '关闭',
		    cancel: true,
			ok : function () {
				$.post("cms/prize/delete?id="+id, function(data) {
					$("#prize_table").jqGrid("setGridParam", {
						datatype : "json"
					}).trigger("reloadGrid", [ {
						page : 1
					} ]);
				});
			}
		});
	}
 
 
	$(function() {
			
		$.jgrid.ajaxOptions.type = 'post';
		$("#prize_table").jqGrid({
			url : "cms/prize/view",
			datatype : "json",
			colModel : [{
				label : '奖品Id',
				name : 'id',
				index : 'id',
				width:50,
				hidden:true
			},{
				label : '奖品名称',
				name : 'prizeName',
				index : 'prizeName',
				width:100
			}, {
				label : '奖品总数',
				name : 'buyTotal',
				index : 'buyTotal',
				width:80
			}, {
				label : '需要金币数',
				name : 'buyMaterial',
				index : 'buyMaterial',
				width:100
			}, {
				label : '奖品已兑换数',
				name : 'buyedTotal',
				index : 'buyedTotal',
				width:100,
				align:'left'
			},{
				label : '奖品剩余数',
				name : 'remaTotal',
				index : 'remaTotal',
				width:80,
				align:'left'
			},{
				label : '状态',
				name : 'status',
				index : 'status',
				formatter:function(cell,options,row){
					if(row.status==1){
						return "待审核";
					}if(row.status==2){
						return "已上架";
					}if(row.status==3){
						return "已售完";
					}if(row.status==4){
						return "已删除";
					}if(row.status==5){
						return "已下架";
					}
					return "";
				}, 
				width:60,
				align:'left'
			},{
				label : '操作',
				name : 'operation',
				index : 'operation',
				width: 50,
				formatter:function(cell,options,row){
					var result = '';
					result = '<a href="#" onclick="modify(\''+row.id+'\')">修改</a>';
					result = result + ' <a href="#" onclick="deletePrize(\''+row.id+'\')">删除</a>';
					return result;
				}
			}],
			height : 370,
			rowNum : 10,
			rowList : [ 10, 20, 30 ],
			viewrecords : true,
			pager : '#pgtoolbar',
			autowidth : true,
			rownumbers : true,
			jsonReader : {
				root : "data",//当前记录
				page : "index",
				records : "totalRecord",//总记录数
				total : 'total',//总页数
				id : 'data.id',
				repeatitems : false
			}
			
		});
		function serialize_list(cell,options,row){
			var result = new Array();
			for(var i=0;i<cell.length;i++){
				result[i] = cell[i].name;
			}
			return result.join(';');
		};
	

		$("#query").click(function() {
			var param = {};			
			var paramArray = $('#qForm').serializeArray();
			for (var i in paramArray) {
				param[paramArray[i].name] = paramArray[i].value;
			}
			var postData = $("#prize_table").jqGrid("getGridParam","postData");
			$.extend(postData, param);
			$("#activity_table").jqGrid("setGridParam", {
				datatype : "json"
			}).trigger("reloadGrid", [ {
				page : 1
			} ]);
		});
		 
	});
	
	function modify(id){
		to_page('/cms/prize/modify/page?id='+id);
	}
</script>